package com.example.qxfw.dataBaseManager.nyzjk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.qxfw.common.entity.ny.AgriServiceIndex;
import com.example.qxfw.common.mapper.AgriServiceIndexMapperXml;
import com.example.qxfw.dataBaseManager.nyzjk.service.NshdzbkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/6  星期四   0:55
 * @description : 此类用来
 ***************************************/
@Service
public class NshdzbkServiceImpl implements NshdzbkService {

    @Autowired
    private AgriServiceIndexMapperXml agriServiceIndexMapperXml;


    @Override
    public List<AgriServiceIndex> selectDistinct(final String column) {
        List<AgriServiceIndex> agriServiceIndexList = this.agriServiceIndexMapperXml.selectDistinct(column);
        return agriServiceIndexList;
    }

    @Override
    public List<AgriServiceIndex> selectAll() {
        return this.agriServiceIndexMapperXml.selectList(null);
    }

    @Override
    public List<AgriServiceIndex> queryList(final AgriServiceIndex agriServiceIndex) {
        return agriServiceIndexMapperXml.selectList(new LambdaQueryWrapper<AgriServiceIndex>()
                .like(StringUtils.isNotBlank(agriServiceIndex.getIndexname()), AgriServiceIndex::getIndexname, agriServiceIndex.getIndexname())
                .like(StringUtils.isNotBlank(agriServiceIndex.getConditiontype()), AgriServiceIndex::getConditiontype, agriServiceIndex.getConditiontype())
                .like(StringUtils.isNotBlank(agriServiceIndex.getWeatherelement()), AgriServiceIndex::getWeatherelement, agriServiceIndex.getWeatherelement())
                .like(StringUtils.isNotBlank(agriServiceIndex.getWeatherlevel()), AgriServiceIndex::getWeatherlevel, agriServiceIndex.getWeatherlevel())
                .orderByAsc(AgriServiceIndex::getIndexname, AgriServiceIndex::getConditiontype));
    }

    @Override
    public Integer updateAgriServiceIndex(final AgriServiceIndex agriServiceIndex) {
        return this.agriServiceIndexMapperXml.updateById(agriServiceIndex);
    }

    @Override
    public Integer deleteAgriServiceIndex(final String id) {
        return this.agriServiceIndexMapperXml.deleteById(id);
    }

    @Override
    public Integer selectCount() {
        return this.agriServiceIndexMapperXml.selectCount(null);
    }

    @Override
    public List<AgriServiceIndex> querySelect5(final AgriServiceIndex agriServiceIndex) {
        return agriServiceIndexMapperXml.selectList(new LambdaQueryWrapper<AgriServiceIndex>()
                .eq(StringUtils.isNotBlank(agriServiceIndex.getIndexname()), AgriServiceIndex::getIndexname, agriServiceIndex.getIndexname())
                .eq(StringUtils.isNotBlank(agriServiceIndex.getConditiontype()), AgriServiceIndex::getConditiontype, agriServiceIndex.getConditiontype())
                .eq(StringUtils.isNotBlank(agriServiceIndex.getWeatherelement()), AgriServiceIndex::getWeatherelement, agriServiceIndex.getWeatherelement())
                .eq(StringUtils.isNotBlank(agriServiceIndex.getCondition()), AgriServiceIndex::getCondition, agriServiceIndex.getCondition())
                .eq(StringUtils.isNotBlank(agriServiceIndex.getNtimes()), AgriServiceIndex::getNtimes, agriServiceIndex.getNtimes())
                .eq(StringUtils.isNotBlank(agriServiceIndex.getWeatherlevel()), AgriServiceIndex::getWeatherlevel, agriServiceIndex.getWeatherlevel())
        );
    }

    @Override
    public String selectMaxId() {
        return agriServiceIndexMapperXml.selectOne(new LambdaQueryWrapper<AgriServiceIndex>()
                        .orderByDesc(AgriServiceIndex::getId).last("LIMIT 1"))
                .getId();
    }

    @Override
    public Integer saveAgriServiceIndex(final AgriServiceIndex agriServiceIndex) {
        int insertSelective = this.agriServiceIndexMapperXml.insertSelective(agriServiceIndex);
        return insertSelective;
    }
}
